/**
 * 作者: wgx
 * 日期: 2025-02-28 17:41:40
 * 备注: 用户已婚子嗣表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserChildMarry;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserChildMarryModel extends BaseModel implements Model {
    public static final String LISTKEY = "user_id";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = true;// 是否需要额外的有序列表

    protected long id; // id
    protected long userId; // 玩家id
    protected String name = ""; // 我方子嗣的名称
    protected int quality; // 品质(形象)
    protected int career; // 职业(形象)
    protected int partner; // 父亲(形象)
    protected int secretary; // 母亲(形象)
    protected int appearance; // 外观(形象) (0表示长相随父亲，取partner字段去partner_main表找头（其他值就根据secretary去secretary_main表找头），身体根据career去child_career_appearance表找)
    protected byte sex; // 性别(形象) (0女1男)
    protected long marryTime; // 结婚时间
    protected long earnAdd; // 毕业时总的城市收益加成
    protected long userIdTarget; // 玩家id对方
    protected String nameTarget = ""; // 对方的子嗣名称
    protected int qualityTarget; // 品质(形象)对方
    protected int careerTarget; // 职业(形象)对方
    protected int partnerTarget; // 父亲(形象)对方
    protected int secretaryTarget; // 母亲(形象)对方
    protected int appearanceTarget; // 外观(形象)对方 (0表示长相随父亲，取partner字段去partner_main表找头（其他值就根据secretary去secretary_main表找头），身体根据career去child_career_appearance表找)
    protected long earnAddTarget; // 毕业时总的城市收益加成对方
    protected String userNameTarget = ""; // 对方的玩家名称

    public void reset() {
    }

    protected String getKey() {
        return "UserChildMarry." + id;
    }

    protected String getListKey() {
        return "UserChildMarry." + userId;
    }

    protected String getListItemKey() {
        return id + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_child_marry"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, userId, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, userId, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // id
        obj.put("userId", userId); // 玩家id
        obj.put("name", name); // 我方子嗣的名称
        obj.put("quality", quality); // 品质(形象)
        obj.put("career", career); // 职业(形象)
        obj.put("partner", partner); // 父亲(形象)
        obj.put("secretary", secretary); // 母亲(形象)
        obj.put("appearance", appearance); // 外观(形象) (0表示长相随父亲，取partner字段去partner_main表找头（其他值就根据secretary去secretary_main表找头），身体根据career去child_career_appearance表找)
        obj.put("sex", sex); // 性别(形象) (0女1男)
        obj.put("marryTime", marryTime); // 结婚时间
        obj.put("earnAdd", earnAdd); // 毕业时总的城市收益加成
        obj.put("userIdTarget", userIdTarget); // 玩家id对方
        obj.put("nameTarget", nameTarget); // 对方的子嗣名称
        obj.put("qualityTarget", qualityTarget); // 品质(形象)对方
        obj.put("careerTarget", careerTarget); // 职业(形象)对方
        obj.put("partnerTarget", partnerTarget); // 父亲(形象)对方
        obj.put("secretaryTarget", secretaryTarget); // 母亲(形象)对方
        obj.put("appearanceTarget", appearanceTarget); // 外观(形象)对方 (0表示长相随父亲，取partner字段去partner_main表找头（其他值就根据secretary去secretary_main表找头），身体根据career去child_career_appearance表找)
        obj.put("earnAddTarget", earnAddTarget); // 毕业时总的城市收益加成对方
        obj.put("userNameTarget", userNameTarget); // 对方的玩家名称
        return obj;
    }

    public PBUserChildMarry.Builder takeInitBuilder() {
        PBUserChildMarry.Builder sb = PBUserChildMarry.newBuilder();
        if (!name.isEmpty()) {
            sb.setName(name);
        }
        if (quality != 0) {
            sb.setQuality(quality);
        }
        if (career != 0) {
            sb.setCareer(career);
        }
        if (partner != 0) {
            sb.setPartner(partner);
        }
        if (secretary != 0) {
            sb.setSecretary(secretary);
        }
        if (appearance != 0) {
            sb.setAppearance(appearance);
        }
        if (sex != 0) {
            sb.setSex(sex);
        }
        if (marryTime != 0) {
            sb.setMarryTime(marryTime);
        }
        if (earnAdd != 0) {
            sb.setEarnAdd(earnAdd);
        }
        if (userIdTarget != 0) {
            sb.setUserIdTarget(userIdTarget);
        }
        if (!nameTarget.isEmpty()) {
            sb.setNameTarget(nameTarget);
        }
        if (qualityTarget != 0) {
            sb.setQualityTarget(qualityTarget);
        }
        if (careerTarget != 0) {
            sb.setCareerTarget(careerTarget);
        }
        if (partnerTarget != 0) {
            sb.setPartnerTarget(partnerTarget);
        }
        if (secretaryTarget != 0) {
            sb.setSecretaryTarget(secretaryTarget);
        }
        if (appearanceTarget != 0) {
            sb.setAppearanceTarget(appearanceTarget);
        }
        if (earnAddTarget != 0) {
            sb.setEarnAddTarget(earnAddTarget);
        }
        if (!userNameTarget.isEmpty()) {
            sb.setUserNameTarget(userNameTarget);
        }
        return sb;
    }

    public PBUserChildMarry.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserChildMarry.Builder sb = PBUserChildMarry.newBuilder();
        if (isFieldUpdate("name")) {
            sb.setName(name);
        }
        if (isFieldUpdate("quality")) {
            sb.setQuality(quality);
        }
        if (isFieldUpdate("career")) {
            sb.setCareer(career);
        }
        if (isFieldUpdate("partner")) {
            sb.setPartner(partner);
        }
        if (isFieldUpdate("secretary")) {
            sb.setSecretary(secretary);
        }
        if (isFieldUpdate("appearance")) {
            sb.setAppearance(appearance);
        }
        if (isFieldUpdate("sex")) {
            sb.setSex(sex);
        }
        if (isFieldUpdate("marryTime")) {
            sb.setMarryTime(marryTime);
        }
        if (isFieldUpdate("earnAdd")) {
            sb.setEarnAdd(earnAdd);
        }
        if (isFieldUpdate("userIdTarget")) {
            sb.setUserIdTarget(userIdTarget);
        }
        if (isFieldUpdate("nameTarget")) {
            sb.setNameTarget(nameTarget);
        }
        if (isFieldUpdate("qualityTarget")) {
            sb.setQualityTarget(qualityTarget);
        }
        if (isFieldUpdate("careerTarget")) {
            sb.setCareerTarget(careerTarget);
        }
        if (isFieldUpdate("partnerTarget")) {
            sb.setPartnerTarget(partnerTarget);
        }
        if (isFieldUpdate("secretaryTarget")) {
            sb.setSecretaryTarget(secretaryTarget);
        }
        if (isFieldUpdate("appearanceTarget")) {
            sb.setAppearanceTarget(appearanceTarget);
        }
        if (isFieldUpdate("earnAddTarget")) {
            sb.setEarnAddTarget(earnAddTarget);
        }
        if (isFieldUpdate("userNameTarget")) {
            sb.setUserNameTarget(userNameTarget);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getUserId() {
        return userId;
    }

    public void putUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            updateRedisHashField(getKey(), "userId", this.userId);
        }
    }

    public void addUserId(long value) {
        this.userId += value;
        updateRedisHashField(getKey(), "userId", this.userId);
    }

    public String getName() {
        return name;
    }

    public void putName(String name) {
        if (!this.name.equals(name)) {
            this.name = name;
            updateRedisHashField(getKey(), "name", this.name);
        }
    }

    public int getQuality() {
        return quality;
    }

    public void putQuality(int quality) {
        if (this.quality != quality) {
            this.quality = quality;
            updateRedisHashField(getKey(), "quality", this.quality);
        }
    }

    public void addQuality(int value) {
        this.quality += value;
        updateRedisHashField(getKey(), "quality", this.quality);
    }

    public int getCareer() {
        return career;
    }

    public void putCareer(int career) {
        if (this.career != career) {
            this.career = career;
            updateRedisHashField(getKey(), "career", this.career);
        }
    }

    public void addCareer(int value) {
        this.career += value;
        updateRedisHashField(getKey(), "career", this.career);
    }

    public int getPartner() {
        return partner;
    }

    public void putPartner(int partner) {
        if (this.partner != partner) {
            this.partner = partner;
            updateRedisHashField(getKey(), "partner", this.partner);
        }
    }

    public void addPartner(int value) {
        this.partner += value;
        updateRedisHashField(getKey(), "partner", this.partner);
    }

    public int getSecretary() {
        return secretary;
    }

    public void putSecretary(int secretary) {
        if (this.secretary != secretary) {
            this.secretary = secretary;
            updateRedisHashField(getKey(), "secretary", this.secretary);
        }
    }

    public void addSecretary(int value) {
        this.secretary += value;
        updateRedisHashField(getKey(), "secretary", this.secretary);
    }

    public int getAppearance() {
        return appearance;
    }

    public void putAppearance(int appearance) {
        if (this.appearance != appearance) {
            this.appearance = appearance;
            updateRedisHashField(getKey(), "appearance", this.appearance);
        }
    }

    public void addAppearance(int value) {
        this.appearance += value;
        updateRedisHashField(getKey(), "appearance", this.appearance);
    }

    public byte getSex() {
        return sex;
    }

    public void putSex(byte sex) {
        if (this.sex != sex) {
            this.sex = sex;
            updateRedisHashField(getKey(), "sex", this.sex);
        }
    }

    public void addSex(byte value) {
        this.sex += value;
        updateRedisHashField(getKey(), "sex", this.sex);
    }

    public long getMarryTime() {
        return marryTime;
    }

    public void putMarryTime(long marryTime) {
        if (this.marryTime != marryTime) {
            this.marryTime = marryTime;
            updateRedisHashField(getKey(), "marryTime", this.marryTime);
        }
    }

    public void addMarryTime(long value) {
        this.marryTime += value;
        updateRedisHashField(getKey(), "marryTime", this.marryTime);
    }

    public long getEarnAdd() {
        return earnAdd;
    }

    public void putEarnAdd(long earnAdd) {
        if (this.earnAdd != earnAdd) {
            this.earnAdd = earnAdd;
            updateRedisHashField(getKey(), "earnAdd", this.earnAdd);
        }
    }

    public void addEarnAdd(long value) {
        this.earnAdd += value;
        updateRedisHashField(getKey(), "earnAdd", this.earnAdd);
    }

    public long getUserIdTarget() {
        return userIdTarget;
    }

    public void putUserIdTarget(long userIdTarget) {
        if (this.userIdTarget != userIdTarget) {
            this.userIdTarget = userIdTarget;
            updateRedisHashField(getKey(), "userIdTarget", this.userIdTarget);
        }
    }

    public void addUserIdTarget(long value) {
        this.userIdTarget += value;
        updateRedisHashField(getKey(), "userIdTarget", this.userIdTarget);
    }

    public String getNameTarget() {
        return nameTarget;
    }

    public void putNameTarget(String nameTarget) {
        if (!this.nameTarget.equals(nameTarget)) {
            this.nameTarget = nameTarget;
            updateRedisHashField(getKey(), "nameTarget", this.nameTarget);
        }
    }

    public int getQualityTarget() {
        return qualityTarget;
    }

    public void putQualityTarget(int qualityTarget) {
        if (this.qualityTarget != qualityTarget) {
            this.qualityTarget = qualityTarget;
            updateRedisHashField(getKey(), "qualityTarget", this.qualityTarget);
        }
    }

    public void addQualityTarget(int value) {
        this.qualityTarget += value;
        updateRedisHashField(getKey(), "qualityTarget", this.qualityTarget);
    }

    public int getCareerTarget() {
        return careerTarget;
    }

    public void putCareerTarget(int careerTarget) {
        if (this.careerTarget != careerTarget) {
            this.careerTarget = careerTarget;
            updateRedisHashField(getKey(), "careerTarget", this.careerTarget);
        }
    }

    public void addCareerTarget(int value) {
        this.careerTarget += value;
        updateRedisHashField(getKey(), "careerTarget", this.careerTarget);
    }

    public int getPartnerTarget() {
        return partnerTarget;
    }

    public void putPartnerTarget(int partnerTarget) {
        if (this.partnerTarget != partnerTarget) {
            this.partnerTarget = partnerTarget;
            updateRedisHashField(getKey(), "partnerTarget", this.partnerTarget);
        }
    }

    public void addPartnerTarget(int value) {
        this.partnerTarget += value;
        updateRedisHashField(getKey(), "partnerTarget", this.partnerTarget);
    }

    public int getSecretaryTarget() {
        return secretaryTarget;
    }

    public void putSecretaryTarget(int secretaryTarget) {
        if (this.secretaryTarget != secretaryTarget) {
            this.secretaryTarget = secretaryTarget;
            updateRedisHashField(getKey(), "secretaryTarget", this.secretaryTarget);
        }
    }

    public void addSecretaryTarget(int value) {
        this.secretaryTarget += value;
        updateRedisHashField(getKey(), "secretaryTarget", this.secretaryTarget);
    }

    public int getAppearanceTarget() {
        return appearanceTarget;
    }

    public void putAppearanceTarget(int appearanceTarget) {
        if (this.appearanceTarget != appearanceTarget) {
            this.appearanceTarget = appearanceTarget;
            updateRedisHashField(getKey(), "appearanceTarget", this.appearanceTarget);
        }
    }

    public void addAppearanceTarget(int value) {
        this.appearanceTarget += value;
        updateRedisHashField(getKey(), "appearanceTarget", this.appearanceTarget);
    }

    public long getEarnAddTarget() {
        return earnAddTarget;
    }

    public void putEarnAddTarget(long earnAddTarget) {
        if (this.earnAddTarget != earnAddTarget) {
            this.earnAddTarget = earnAddTarget;
            updateRedisHashField(getKey(), "earnAddTarget", this.earnAddTarget);
        }
    }

    public void addEarnAddTarget(long value) {
        this.earnAddTarget += value;
        updateRedisHashField(getKey(), "earnAddTarget", this.earnAddTarget);
    }

    public String getUserNameTarget() {
        return userNameTarget;
    }

    public void putUserNameTarget(String userNameTarget) {
        if (!this.userNameTarget.equals(userNameTarget)) {
            this.userNameTarget = userNameTarget;
            updateRedisHashField(getKey(), "userNameTarget", this.userNameTarget);
        }
    }

}